package com.flink.ttest.cofig;

import org.apache.flink.api.common.functions.AggregateFunction;
import org.apache.flink.api.java.tuple.Tuple3;

import java.math.BigDecimal;

/**
 * @author: LCG
 * @date: 2022-07-01 13:18:45
 * @description:
 **/
public class OrderAggre implements AggregateFunction<Tuple3<String, Long, BigDecimal>,Tuple3<String, Long, BigDecimal>,Tuple3<String, Long, BigDecimal>> {
    @Override
    public Tuple3<String, Long, BigDecimal> createAccumulator() {
        Tuple3<String, Long, BigDecimal> tuple3=new Tuple3<String, Long, BigDecimal>(null,0L,new BigDecimal(0.0));
        return tuple3;
    }

    @Override
    public Tuple3<String, Long, BigDecimal> add(Tuple3<String, Long, BigDecimal> stringLongBigDecimalTuple3, Tuple3<String, Long, BigDecimal> stringLongBigDecimalTuple32) {
        stringLongBigDecimalTuple32.f0=stringLongBigDecimalTuple3.f0;
        stringLongBigDecimalTuple32.f1 = stringLongBigDecimalTuple32.f1 + stringLongBigDecimalTuple3.f1;
        stringLongBigDecimalTuple32.f2 = stringLongBigDecimalTuple3.f2.add(stringLongBigDecimalTuple32.f2);
        return stringLongBigDecimalTuple32;
    }

    @Override
    public Tuple3<String, Long, BigDecimal> getResult(Tuple3<String, Long, BigDecimal> stringLongBigDecimalTuple3) {
        return stringLongBigDecimalTuple3;
    }

    @Override
    public Tuple3<String, Long, BigDecimal> merge(Tuple3<String, Long, BigDecimal> stringLongBigDecimalTuple3, Tuple3<String, Long, BigDecimal> acc1) {

        acc1.f1 = acc1.f1 + stringLongBigDecimalTuple3.f1;
        acc1.f2 = stringLongBigDecimalTuple3.f2.add(acc1.f2);

        return acc1;
    }
}
